<template>
    <view class="container">
        <view class="cd-bg">
            <!-- 基本信息 -->
            <view class="cd-title">
                <uni-row>
                    <uni-col :span="20">
                        <view class="param">基本信息</view>
                    </uni-col>

                </uni-row>
            </view>
            <view class="cd-body">
                <view class="param">
                    <b>发起人：</b>
                    {{ detail.createBy }}
                </view>
                <view class="param">
                    <b>发起时间：</b>
                    {{ getFormatedTimeStr(detail.createTime) }}
                </view>
            </view>

            <!-- 特殊参数 -->
            <view class="cd-line">
                <view class="param">值班信息</view>
            </view>
            <view class="cd-body">
                <view class="param">
                    <b>值班人：</b>
                    {{ nameList }}
                </view>
                <view class="param">
                    <b>值班日期：</b>
                    {{ getFormatedTimeStr1(detail.watchTime) }}
                </view>
                <view class="param">
                    <b>交班人：</b>
                    {{ nameList1 }}
                </view>
                <view class="param">
                    <b>接班人：</b>
                    {{ nameList2 }}
                </view>
                <view class="param">
                    <b>值班内容记录：</b>
                    {{ detail.watchContentRecord }}
                </view>
                <view class="param">
                    <b>事件处理结果：</b>
                    {{ detail.watchResult }}
                </view>
            </view>
        </view>
    </view>
</template>
    
<script>
import { websock } from "../../net/websock";
import {
    prevFile // 预览普通文件
} from "../../utils/preview.js";
import { getzhibanjiluList } from "../../net/zhibanjilu";
import moment from "moment";
export default {
    data() {
        return {
            times: ["接待时间", "就餐时间"],
            people: ["陪同人员", "就餐人员"],
            shiyou: ["接待事由", "申请事由"],
            nameList: [],
            nameList1: [],
            nameList2: [],
            id: 0,
            taskid: 0,
            see: 0,
            itemsd: "",
            itemssd: "",
            approval: [],
            contents: {},
            taskInfo: {},
            detail: {},
            userInfo: {},
        };
    },
    async onReady() {
        try {
            this.userInfo = await websock.getUserInfo();
        } catch (e) {
            uni.showToast({
                title: e.message
            });
        }
    },

    async onLoad(params) {
        console.log(JSON.parse(params.content));
        this.getInfo(JSON.parse(params.content))
    },
    methods: {
        prevFileClick(item) {
            prevFile(item);
        },
        async getInfo(e) {
            //获取所有人
            let arr = []
            const data = await websock.getContactList()
            console.log(data);
            data.forEach(item => {
                if (item.userList) {
                    item.userList.forEach(items => {
                        arr.push({ uid: items.uid, name: items.name })
                    })
                }
            })
            const tbWatchRecord = {
                id: e
            };
            const res = await getzhibanjiluList(tbWatchRecord);
            console.log(res.data[0]);
            this.detail = res.data[0];
            this.detail.createBy = res.data[0].createBy;
            this.detail.createTime = res.data[0].createTime;
            this.detail.watchTime = res.data[0].watchTime;
            this.detail.watchId = res.data[0].watchId;
            this.detail.handoverId = res.data[0].handoverId;
            this.detail.successorId = res.data[0].successorId;
            let name = []
            res.data[0].watchId.split(',').forEach(item => {
                arr.forEach(data => {
                    if (item == data.uid) {
                        name.push(data.name)
                    }
                })
            })

            this.nameList = name.join(',')//显示值班人员名称
            let name1 = []
            res.data[0].handoverId.split(',').forEach(item => {
                arr.forEach(data => {
                    if (item == data.uid) {
                        name1.push(data.name)
                    }
                })
            })

            this.nameList1 = name1.join(',')//显示交班人员名称
            let name2 = []
            res.data[0].successorId.split(',').forEach(item => {
                arr.forEach(data => {
                    if (item == data.uid) {
                        name2.push(data.name)
                    }
                })
            })
            this.nameList2 = name2.join(',')//显示接班人员名称


            this.detail.watchContentRecord = res.data[0].watchContentRecord;
            this.detail.watchResult = res.data[0].watchResult;
        },
        // 获取格式化时间字符串
        getFormatedTimeStr(stamp, str = "YYYY-MM-DD HH:mm:ss") {
            return moment(stamp).format(str);
        },
        getFormatedTimeStr1(stamp, str = "YYYY-MM-DD") {
            return moment(stamp).format(str);
        },
    }
};
</script>
    
<style>
@import url("../common/detail.css");
</style>
    